/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fwdispstartscreen;

import com.sun.java.swing.plaf.windows.WindowsBorders.ProgressBarBorder;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

/**
 *
 * @author rbs
 */
public class StartFrame extends JFrame{

    private JProgressBar progress;
    private JLabel status;
    private JLabel exit;
    private JLabel countdown;
    private boolean autoMode = true; //TODO!!!
    

    public StartFrame() {
        
        
        setUndecorated(true);
        setSize(640, 480);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setContentPane(new BackGroundPane("start_bg.jpg"));
        getContentPane().setLayout(null);

        exit = new JLabel("x");
        add(exit);
        exit.setForeground(Color.red);
        exit.setLocation(623, 1);
        exit.setSize(20,20);
        exit.setFont(new Font("Arial", Font.BOLD, 20));
        exit.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent e) {}

            public void mousePressed(MouseEvent e) {
                System.exit(0);
            }

            public void mouseReleased(MouseEvent e) {}

            public void mouseEntered(MouseEvent e) {}

            public void mouseExited(MouseEvent e) {}
        });

        status = new JLabel();
        add(status);
        status.setLocation(0, 405);
        status.setSize(640, 15);
        status.setForeground(Color.GREEN);
        status.setText("Suche nach Updates...");
        status.setHorizontalAlignment(JLabel.CENTER);

        progress = new JProgressBar();
        add(progress);

        

        progress.setLocation(0, 420);
        progress.setSize(640, 3);
        progress.setBorderPainted(false);
        progress.setBackground(Color.BLACK);
        progress.setForeground(Color.GREEN);

        countdown = new JLabel();
        add(countdown);
        countdown.setLocation(0, 440);
        countdown.setSize(640, 15);
        countdown.setForeground(Color.red);
        countdown.setHorizontalAlignment(JLabel.CENTER);

        setVisible(true);
    }
    public void SetProgress(int val)
    {
        progress.setValue(val);
    }

    public void SetCountdown(int count)
    {
        countdown.setText("" + count);
    }

    public void setStatusMsg(String string) {
        status.setForeground(Color.green);
        status.setText(string);
    }

    public void setStatusBar(int i) {
        progress.setValue(i);
    }

    public void ShowWarnMsgDialog(String msg)
    {
        progress.setForeground(Color.ORANGE);
        status.setForeground(Color.ORANGE);
        status.setText(msg);
        if (!autoMode)
            JOptionPane.showMessageDialog(null, msg, "Warnung", JOptionPane.WARNING_MESSAGE);
    }

    public void ShowErrMsgDialog(String msg)
    {
        progress.setForeground(Color.RED);
        progress.setIndeterminate(true);
        status.setForeground(Color.RED);
        status.setText(msg);
        if (!autoMode)
            JOptionPane.showMessageDialog(null, msg, "Schwerwiegender Fehler", JOptionPane.ERROR_MESSAGE);
        //System.exit(-1);
    }



}


class BackGroundPane extends JPanel {
        Image img = null;
        
        BackGroundPane(String imagefile) {
            if (imagefile != null) {
                MediaTracker mt = new MediaTracker(this);
                img = Toolkit.getDefaultToolkit().getImage(imagefile);
                mt.addImage(img, 0);
                try {
                    mt.waitForAll();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(img,0,0,this.getWidth(),this.getHeight(),this);
        }
    }

